//wxlogin.js
//获取应用实例
var App = getApp();
Page({
  data: {
    rankData: [],
    currentIndex: 0,
    isShowLoading: false,
    username: '',
    password: '',
    region: '',
    gender: 1,
  },
  onLoad: function (options) {
    var self = this;
  },
  //监听用户输入
  userInput: function (event) {
    var self = this;
    var type = event.target.dataset.type;
    switch (type) {
      case 'username':
        self.setData({ username: event.detail.value });
        break;
      case 'password':
        self.setData({ password: event.detail.value });
        break;
      case 'region':
        self.setData({ region: event.detail.value });
        break;
    }
    console.info("self.data.username", self.data.username);
    console.info("self.data.password", self.data.password);
    console.info("self.data.region", self.data.region);
  },
  //用户改变性别
  genderChange: function (event) {
    var self = this;
    var genderSelect = (event.target.dataset.gender == 'male' ? 1 : 0);
    self.setData({   gender: genderSelect  })

    console.info("self.data.gender", self.data.gender);
  },
  bindRegionChange: function (e) {
    this.setData({
      region: e.detail.value
    })
    console.info("self.data.region", this.data.region);
  },
  confirmRegiste:function(e){

    if (this.data.username < 1) {
      App.showError("手机号不能为空");
      this.data.error = '手机号不能为空';
      return false;
    }
   
    let reg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (!reg.test(this.data.username)) {
      App.showError("手机号不符合要求");
      this.data.error = '手机号不符合要求';
      return false;
    }
    if (this.data.password < 8) {
      App.showError("密码长度不能小于8");
      this.data.error = '密码长度不能小于8';
      return false;
    }
    if (!this.data.region) {
      App.showError("省市区不能空");
      this.data.error = '省市区不能空';
      return false;
    }

    App._post_form("user/info",{
      username:this.data.username,
      password:this.data.password,
      gender:this.data.gender,
      region:this.data.region
    }, function (result) {
      console.log("infomation", result);
      if (result.status == 200) {
        wx.showModal({
          title: "提示",
          showCancel: false,
          content: "完善成功！",
          success: function (o) {
            wx.switchTab({
              url: '../index/index'
            })
          }
        });

      }
    })
  },
  gotoIndex: function () {
    console.info("success","1111");
    wx.switchTab({
      url: '../index/index'
    })
  },
});